const app = getApp();
Page({
    data: {
        indexData:'',
        netErr: 0,
    },
    onLoad() {
    },
    onShow(){
        this.indexAjax();
    },
    /*商户页请求*/
    indexAjax(){
        app.request.request({
            link: '/api/supplier/merchant_info',
            methodtype: 'GET',
            succ: (res) => {
                console.log(app.globalData.my)
                let indexBox = res.data.data, BoxMeta = res.data.message, indexData = this.data.indexData;
                if (res.data.status == 200) {
                    indexBox.logo = app.request.picAdd + indexBox.logo;
                    indexBox.is_brand = app.globalData.brand.is_brand;
                    this.setData({
                        indexData: indexBox,
                    })
                } else {
                    app.util.showModal(false, '提示', BoxMeta, () =>{
                        wx.removeStorage({
                            key: 'fyzs_info',
                            success: (res) => {
                                app.request.must.merchant_id = '';
                                wx.reLaunch({
                                    url: '/pages/login/login'
                                })
                            }
                        })
                    })
                }
            },
            fail:(err)=>{
                this.setData({
                    netErr: 1,
                })
            },
            loadtype: this.data.indexData ? 1 : 0,
        })
    },
    /*下拉刷新*/
    onPullDownRefresh() {
        this.ErrorF5();
        setTimeout(() => {
            wx.stopPullDownRefresh();
        }, 500)
    },
    /*调起微信扫描*/
    Scaveng: function () {
        wx.scanCode({
            success: (res) => {
                let url = res.result, link ='/pages/proveOrder/proveOrder';
                console.log(res.result)
                if (url.substring(0, link.length) === link) {
                    wx.navigateTo({
                        url: url,
                    })
                } else {
                    app.util.showModal(false, '提示', '没找到相关信息')
                }
            }
        })
    },
    /*进入核销*/
    proveJump(){
        wx.navigateTo({
            url: '/pages/proveOrder/proveOrder?input=1',
        })
    },
    /*我的营业订单*/
    businOrderJump(e){
        wx.navigateTo({
            url: '/pages/businOrder/businOrder',
        })
    },
    /*切换分店*/
    switchJump() {
        wx.navigateTo({
            url: '/pages/replace/replace',
        })
    },
    /*退出*/
    Signout: function () {
        app.util.showModal(true, '退出', '是否确认退出', () => {
            wx.removeStorage({
                key: 'fyzs_info',
                success: (res) => {
                    wx.removeStorage({
                        key: 'fyzs_brand',
                        success: (res) => {
                            delete app.request.must.merchant_id;
                            delete app.globalData.my;
                            delete app.globalData.brand;
                            app.util.Success('退出成功', () => {
                                setTimeout(() => {
                                    wx.reLaunch({
                                        url: '/pages/login/login'
                                    })
                                }, 1500)
                            });
                        }
                    })    
                }
            })
        })
    },
    /*财务结算*/
    financeJump(){
        wx.navigateTo({
            url: '/pages/SetOrder/SetOrder',
        })
    },
    /*酒店管理*/
    hotelJump() {
        app.util.showModal(false, '提示', '暂未开放')
    },
    changePass(){
        wx.navigateTo({
            url: '/pages/Changepass/Changepass',
        })
    },
    /*网络报错*/
    ErrorF5(){
        this.setData({
            indexData: '',
            netErr: 0,
        })
        this.indexAjax();
    },
})